package com.violet.controller.manager;

import com.violet.domain.result.Result;
import com.violet.domain.result.ResultPage;
import com.violet.domain.search.MyPage;
import com.violet.domain.search.manager.MOrderSearch;
import com.violet.domain.vo.manager.MOrderVo;
import com.violet.service.manager.MOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/order")
@RequiredArgsConstructor
public class MOrderController {

    private final MOrderService service;

    // 分页查询
    @GetMapping("/search")
    public ResultPage<List<MOrderVo>> search(@ModelAttribute MOrderSearch search, @ModelAttribute MyPage myPage) {
        return service.search(search, myPage);
    }

    // 将待配送的订单置为配送中
    @GetMapping("/delivery")
    public Result<Boolean> delivery(@RequestParam String orderId, @RequestParam String riderId) {
        return Result.success(service.delivery(orderId, riderId), "修改为配送中");
    }

    // 取消订单
    @GetMapping("/cancel")
    public Result<Boolean> cancel(@RequestParam String id) {
        return Result.success(service.cancel(id), "取消订单");
    }

    // 完成一个订单
    @GetMapping("/complete")
    public Result<Boolean> complete(@RequestParam String id) {
        return Result.success(service.complete(id), "完成订单");
    }

}
